import re

from common.db.common_db_handler import session
from .models import User


def register_handler(params):
    try:
        email = params.get("email")
        rex = r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"
        if not re.match(rex, email):
            return {"code": 500, "msg": "邮箱格式不正确"}
        res = session.add(User, **params)
        if not res:
            return {"code": 500, "msg": "添加失败"}
        return {"code": 200, "msg": "添加成功"}
    except Exception as e:
        print("333333", e)
        return {"code": 500, "msg": "添加失败"}

